<?php
$g4_path = "../"; 
require_once ($g4_path.'common.php');

$title = "강의관리";
$menu = 1;
$_sqlWhere = $cateLink = NULL; 
require_once ('./admin.head.php');
require_once ('./admin.lib.php');

$tpl = new Template_;
$tpl->template_dir = './tpl';
$tpl->compile_dir = './tpl/compile';

$nowPage = isset($_GET['page']) ? $_GET['page'] : 1; 
$perPage = 10; 
$_res = sql_fetch("SELECT count(no) as cnt FROM course".$_sqlWhere);
$totalPage = ceil($_res['cnt']/$perPage);
if(($nowPage > $totalPage) || ($nowPage < 1)) {
    alert("페이지 번호가 잘못되었습니다.", './courseManage.php?list');
}
$_sqlLimitPage = ($nowPage-1)*$perPage; 
$_sqlOrder = " ORDER BY no DESC"; 
$_sqlLimit = " LIMIT $_sqlLimitPage, $perPage"; 
$sql = 'SELECT * FROM course'.$_sqlWhere.$_sqlOrder.$_sqlLimit;

require_once ('./admin.head.php');

$_res = sql_query($sql);
while($_ret = sql_fetch_array($_res)) {

    $_temp = sql_fetch("SELECT mb_name FROM g4_member WHERE `mb_no`=".$_ret['teacher']);
    $_ret['teachername'] = $_temp['mb_name']; 
    $_temp = sql_fetch("SELECT name FROM book WHERE `no`=".$_ret['bookcode']);
    $_ret['bookname'] = $_temp['name']; 
    $data[] = $_ret; 
}

if(!$totalPage) {
    $_tplSetting['nodata'] = TRUE; 
}

$_tplSetting['paging'] = get_paging($perPage,$nowPage,$totalPage,"./bookManage.php?page=",makelink(array('page')));
$tpl->assign('data', $data);
$tpl->assign('set', $_tplSetting);
$tpl->define('basic',"courseManage.html");
$tpl->print_('basic');
